package com.tianhai.db.parser.ast;

import java.util.List;

/**
 * UPDATE语句AST节点
 */
public class UpdateStatement extends Statement {
    
    private final String tableName;
    private final List<Assignment> assignments;
    private final SelectStatement.WhereClause whereClause;
    
    public UpdateStatement(String tableName, List<Assignment> assignments, 
                          SelectStatement.WhereClause whereClause) {
        this.tableName = tableName;
        this.assignments = assignments;
        this.whereClause = whereClause;
    }
    
    @Override
    public StatementType getType() {
        return StatementType.UPDATE;
    }
    
    public String getTableName() {
        return tableName;
    }
    
    public List<Assignment> getAssignments() {
        return assignments;
    }
    
    public SelectStatement.WhereClause getWhereClause() {
        return whereClause;
    }
    
    @Override
    public String toString() {
        return "UpdateStatement{" +
                "tableName='" + tableName + '\'' +
                ", assignments=" + assignments +
                ", whereClause=" + whereClause +
                '}';
    }
    
    /**
     * 赋值语句
     */
    public static class Assignment {
        private final String columnName;
        private final Object value;
        
        public Assignment(String columnName, Object value) {
            this.columnName = columnName;
            this.value = value;
        }
        
        public String getColumnName() {
            return columnName;
        }
        
        public Object getValue() {
            return value;
        }
        
        @Override
        public String toString() {
            return columnName + " = " + value;
        }
    }
}
